package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.domain.OfComment;
import cn.wolfcode.trip.base.mapper.CommentMapper;
import cn.wolfcode.trip.base.mapper.OfCommentMapper;
import cn.wolfcode.trip.base.service.IOfCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OfCommentServiceImpl implements IOfCommentService {

    @Autowired
    private OfCommentMapper ofCommentMapper;
    @Autowired
    private CommentMapper commentMapper;


    @Override
    public void addOfComment(OfComment ofComment) {
        //传递过来点赞人的ID 评论的ID
        //通过评论ID获取评论对象
        Long id = ofComment.getComment().getId();
        Comment comment = commentMapper.selectCommentByPrimaryKey(id);
        ofComment.setCommentator(comment.getCommentator());
        ofComment.setDate(new Date());
        ofCommentMapper.insert(ofComment);

    }

    @Override
    public int getOfCommentsLikeNums(Long commentId) {
        return ofCommentMapper.getOfCommentLikeNums(commentId);
    }

    @Override
    public List<OfComment> getOfCommentsListByUserId(Long commentId) {
        return ofCommentMapper.getOfCommentsListByUserId(commentId);
    }

    @Override
    public void addOfsubComm(OfComment ofComment) {
        Long id = ofComment.getComment().getId();
        Comment comment = commentMapper.selectCommentByPrimaryKey(id);
        ofComment.setCommentator(comment.getCommentator());
        ofComment.setDate(new Date());
        ofCommentMapper.addOfsubComm(ofComment);
    }

}
